//  tab点击切换
$('.tabs-nav a').on('touchstart', function() {
    $('.am-tabs-bd').css({ 'display':'block' });
    $('.am-tabs-nav > li').removeClass('am-active');
    $(this).parent().addClass('am-active');
    $('.am-tabs-bd div').removeClass('am-active');
    var tabsNum = $(this).attr('data-kuai-tabs');
    var aTabs = $('.am-tabs-bd div');
    $(aTabs[tabsNum]).addClass('am-active');
});

$('.am-tabs-nav a').on('touchstart', function() {
    $('.am-tabs-nav > li').removeClass('am-active');
    $(this).parent().addClass('am-active');
    $('.am-tabs-bd div').removeClass('am-active');
    var tabsNum = $(this).attr('data-kuai-tabs');
    var aTabs = $('.am-tabs-bd div');
    $(aTabs[tabsNum]).addClass('am-active');
});

$('#kuaikuai-btn button.am-btn-buy').on('touchstart', function() {
    location.href = 'pay.html';
});

$('#kuaikuai-btn button.am-btn-cancel').on('touchstart', function() {
    location.href = 'detailProduct.html';
});

// 地图蒙版
$modal = $('#map-modal');
$('a.view').on('click', function() {
    $modal.modal('toggle');
});

//  星星评价
var iStar = 5;

$li = $('#kuaikuai-header').find('i');
for(var i = 1; i <= $li.length; i++) {
    $li[i - 1].index = i;
    $($li[i - 1]).on('click', function () {
        fnPoint(this.index);
    });
}

//  评分处理
function fnPoint(iArg)
{
    //分数赋值
    iScore = iArg || iStar;
    for (i = 0; i < $li.length; i++) $li[i].className = i < iScore ? "ui-fonts icon-un" : "ui-fonts";
}

$txt = $('#kuaikuai-textarea span em').text();

//  文本框评价
$('.kuaikuai-comment button').on('touchstart', function () {
    $this = $(this);
    $thisVal = $('#kuaikuai-textarea textarea').val();
    if ($thisVal == '' || $thisVal.length > 500) {
        alert("请输入500字以内评价");
    }
});

$('#kuaikuai-textarea textarea').on('change', function () {
    $thisVal = $('#kuaikuai-textarea textarea').val();
    $last = $txt - $thisVal.length;
    if ($last < 0) {
        $('#kuaikuai-textarea span em').css({ 'color':'red' });
    } else {
        $('#kuaikuai-textarea span em').css({ 'color':'#000' });
    }
    $('#kuaikuai-textarea span em').html($last);
});

// 选择1
$aRadio = $('#am-gallery li a');
$aRadio.on('click', function () {
    $this = $(this);
    for(var i = 0; i < $aRadio.length; i++) {
        $($aRadio[i]).find('.r-btn').removeClass('rg');
}
    $this.find('.r-btn').addClass('rg');
});

$aRadio2 = $('#select-gallery li a');
$aRadio2.on('click', function () {
    $this = $(this);
    for(var i = 0; i < $aRadio2.length; i++) {
        $($aRadio2[i]).find('.r-btn').removeClass('rg');
    }
    $this.find('.r-btn').addClass('rg');
});

//  选择
$('#select-btn button').on('touchstart', function () {
    $car = $('#car-num b');
    $rg = $('#select-gallery a').find('.rg');
    $car.html($rg.parent().text());

    if ($('#my-popup').hasClass('am-modal-out')) {
        $('#my-popup').removeClass('am-modal-out');
        $('#my-popup').addClass('am-model-active');
    } else {
        $('#my-popup').removeClass('am-model-active');
        $('#my-popup').addClass('am-modal-out');
        $('#my-popup').removeAttr('style');
    }
});

$number = $('#number').val();
//  添加
$('#plus').on('touchstart', function (){
    $number++;
    $('#number').val($number);
});

//  减少
$('#minus').on('touchstart', function (){
    if($number > 1) {
        $number--;
    } else {
        $number = 1;
    }
    $('#number').val($number);
});

// 发布评价
$('#kcomment').on('touchstart', function () {
    location.href = 'comment.html';
});

